#pragma GCC optimize(2)
#include <iostream>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <unordered_set>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int N=2e6+10;
char s[N];
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
	     ll n,m;
	     scanf("%lld %lld %s",&n,&m,s+1);
	     vector<int> zero(n+5,-1);
	     vector<int> one (n+5,-1);
	     for(int i=1;i<=n;i++)
	     {
	     	zero[i]=zero[i-1];
	     	if(s[i]=='0') zero[i]=i;
		 }
		 for(int i=n;i>=1;i--)
		 {
		 	one[i]=one[i+1];
		 	if(s[i]=='1') one[i]=i;
		 }
		 set<pii> st;
		 while(m--)
		 {
		 	int l,r;
		 	cin>>l>>r;
		 	l=one[l];
		 	r=zero[r];
		 	if(l>=r || l==-1 || r==-1) l=-1,r=-1;
		 	st.insert({l,r});
		 }
		 cout<<st.size()<<endl;
	}

	return 0;
}


